﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using lumo.display.object2D;
using lumo.input;
using Microsoft.Xna.Framework;

namespace lumo.display.animation2D
{
    /// <summary>
    /// An animation to permanently follow the cursor.
    /// </summary>
    public class CursorFollowAnimation2D : GenericAnimation2D<IPositionable2D>
    {
        // Private variables
        private Cursor  Cursor;
        private Counter CursorXCounter = new Counter();
        private Counter CursorYCounter = new Counter();

        /// <summary>
        /// Constructor
        /// </summary>
        public CursorFollowAnimation2D(Cursor Cursor, float Time, Smooth Smoothness = Smooth.None, IPositionable2D CurrentObject = null)
            : base(Time, Smoothness, Loop.None, CurrentObject)
        {
            this.Cursor = Cursor;
        }

        /// <summary>
        /// Never finishes
        /// </summary>
        public override bool Finished { get { return false; } }

        /// <summary>
        /// Setup the values
        /// </summary>
        internal override void SetupValues()
        {
            CursorXCounter.Reset(this.CurrentObject.X, this.Cursor.X, this.Time, this.Smoothness, Loop.None);
            CursorYCounter.Reset(this.CurrentObject.Y, this.Cursor.Y, this.Time, this.Smoothness, Loop.None);
        }

        /// <summary>
        /// Update the values.
        /// </summary>
        /// <param name="Game">The game class</param>
        internal override void UpdateValues(LumoComponent Game)
        {
            if (CursorXCounter.To != this.Cursor.X)
                CursorXCounter.Reset(this.CurrentObject.X, this.Cursor.X, this.Time, this.Smoothness, Loop.None);
            if (CursorYCounter.To != this.Cursor.Y)
                CursorYCounter.Reset(this.CurrentObject.Y, this.Cursor.Y, this.Time, this.Smoothness, Loop.None);
            CursorXCounter.Update(Game);
            CursorYCounter.Update(Game);
            this.CurrentObject.Position = new Vector2(CursorXCounter.Value, CursorYCounter.Value);
        }
    }
}
